//
//  BaseViewController.swift
//  UserApp_iOS
//
//  Created by linlin on 2019/9/6.
//  Copyright © 2019 linlin. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    var hidesNavigationBar: Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        navigationController?.setNavigationBarHidden(hidesNavigationBar, animated: false)
    }
    
    func addSearchBar() -> UISearchBar{
        let titleView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.width-150, height: 40));
        let searchBar = UISearchBar(frame: titleView.bounds)
        var searchTextField : UITextField?
        
        if #available(iOS 13.0, *) {
            searchTextField = searchBar.searchTextField
        } else {
            for subView in searchBar.subviews {
                for subsubView in subView.subviews {
                    if let stf = subsubView as? UITextField {
                        searchTextField = stf
                    }
                }
            }
        }
        
        searchTextField?.font = UIFont.systemFont(ofSize: 14)
        searchBar.setSearchFieldBackgroundImage(UIImage(named: "icon_check"), for: .normal)
        searchBar.placeholder = "请输入品牌/车型/配件等关键字"
        titleView.addSubview(searchBar)
        self.navigationItem.titleView = titleView
        return searchBar
    }
        
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
    
}
